#ifndef _PYTHONTREEBUILDER_H_
#define _PYTHONTREEBUILDER_H_
#include "CtxVisitor.h"
#include "ast/Suite.h"
#include "ast/DefaultArg.h"
#include "ast/ComprehensionCollection.h"

class JJTState;
class StmtTypeList;

class PythonTreeBuilder
{
public:
    PythonTreeBuilder(JJTState* stack);

    SimpleNodePtr getLastOpened();

    SimpleNodePtr openNode(int id);
    SimpleNodePtr closeNode(const SimpleNodePtr& n, int arity);
    SimpleNodePtr onCloseNode(const SimpleNodePtr& n, int arity);
private:
    StmtTypeList makeStmts(int l);
    StmtTypeList popSuite();
    SuitePtr popSuiteAndSuiteType();
    void addSpecialsAndClearOriginal(const SimpleNodePtr& from, const SimpleNodePtr& to);
    void addSpecials(const SimpleNodePtr& from, const SimpleNodePtr& to);
    void addSpecialsBefore(const SimpleNodePtr& from, const SimpleNodePtr& to);
    StmtTypeList getBodyAndSpecials();
    SimpleNodePtr handleIfConstruct(const SimpleNodePtr& n, int arity);
    SimpleNodePtr makeDecorator(const QList<SimpleNodePtr>& nodes);
    bool isArg(const SimpleNodePtr& n);
    ExprTypeList makeExprs();
    ExprTypeList makeExprs(int l);
    AliasTypeList makeAliases(int l);
    NameTokPtr makeName(int ctx);
    NameTokPtr makeName(int ctx, const NamePtr& name);
    argumentsTypePtr makeArguments(int l);
    argumentsTypePtr __makeArguments(const QList<DefaultArgPtr>& def, const NameTokPtr& varg, const NameTokPtr& kwarg);
    void setParentForFuncOrClass(const StmtTypeList& body, const stmtTypePtr& classDef);
    NameTokList makeIdentifiers(int ctx);
    NameTokList makeIdentifiers(int ctx, int arity);
    SimpleNodePtr makeWithStmt(int arity);
    SimpleNodePtr makeWithItem(int arity);
    SimpleNodePtr makeTuple(const SimpleNodePtr& n);
    SimpleNodePtr makeDictionaryOrSet(int arity);
    ComprehensionCollectionPtr makeCompFor(int arity);
    SimpleNodePtr makeImportFrom25Onwards(int arity);

    JJTState*   _stack;
    SimpleNodePtr _lastOpened;
    CtxVisitor  _ctx;
    SimpleNodePtr _lastPop;
};

#endif
